package com.zmx.common.common.service;

import com.zmx.common.common.utils.DateUtil;
import com.zmx.common.common.utils.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Description: 接收处理日志基础service类
 * @ClassName: ReceiveBaseService
 * @Author zhaomxr
 * @Date 2021-08-30 11:22
 */
@Slf4j
@Component
public abstract class ReceiveBaseService<T> {

    @RabbitHandler
    @RabbitListener(queues = "info")
    public void receiveInfo(T t) {
        System.out.println(String.format("%s ERROR --- [%s]:%s", DateUtil.getDateTime(), Thread.currentThread().getName(), JacksonUtil.toJsonString(t)));
    }

    @RabbitHandler
    @RabbitListener(queues = "error")
    public void receiveError(T t) {
        System.out.println(String.format("%s ERROR --- [%s] : %s", DateUtil.getDateTime(), Thread.currentThread().getName(), JacksonUtil.toJsonString(t)));
    }

    @RabbitHandler
    @RabbitListener(bindings = @QueueBinding(value = @Queue("info"), exchange = @Exchange(value = "log"), key = "info"))
    public void receiveLogInfo(T t) {
        System.out.println(String.format("%s ERROR --- [%s]:%s", DateUtil.getDateTime(), Thread.currentThread().getName(), JacksonUtil.toJsonString(t)));
    }

    @RabbitHandler
    @RabbitListener(bindings = @QueueBinding(value = @Queue("error"), exchange = @Exchange("log"), key = "error"))
    public void receiveLogError(T t) {
        System.out.println(String.format("%s ERROR --- [%s] : %s", DateUtil.getDateTime(), Thread.currentThread().getName(), JacksonUtil.toJsonString(t)));
    }
}
